package apiwork.lcbmi.util.config;


import java.util.HashMap;
import java.util.Map;

import com.linkage.util.config.MemoryConfig;
import com.linkage.util.config.SystemConfig;
import com.linkage.util.xml.XMLProperties;

public class OtherConfig extends MemoryConfig{
	private static OtherConfig m_instance = null;
	private static XMLProperties xmlProperties = null;
	private String configName = ""; 
	
	private OtherConfig(){}
	
	public static OtherConfig getInstance() {
		if (m_instance == null) {
			m_instance = new OtherConfig();
		}
		return m_instance;
	}
	
	synchronized public void reload() throws Exception {
		try{
			if(isReload() || xmlProperties == null){
				String xmlFile = SystemConfig.getInstance().getConfig(configName);
				xmlProperties = new XMLProperties(xmlFile);
			}
			setReload(false);
		}catch(Exception e){
			throw new Exception(e);
		}
	}
	
	public String getProperties(String name) throws Exception{
		try{
			reload();
			return xmlProperties.getElementValue(name);
		}catch(Exception e){
			e.printStackTrace();
			return "";
		}
    }

	public Map getAllSubElementInfo(String name,boolean includeAttribute) throws Exception {
		try{
			reload();
			if (null != name) {
				return xmlProperties.getAllSubElementInfo(xmlProperties.getElement(name),includeAttribute);
			}else{
				return xmlProperties.getAllSubElementInfo(xmlProperties.getRootElement(),includeAttribute);
			}
		}catch(Exception e){
			e.printStackTrace();
			return new HashMap();
		}
	}
	
	public String getConfigName() {
		return configName;
	}

	public void setConfigName(String configName) {
		this.configName = configName;
	}
}
